//
//  MTServerCrachView.swift
//  MT
//
//  Created by zhang qiang on 2018/12/2.
//  Copyright © 2019年 张强. All rights reserved.
//

import Foundation
import UIKit
import Then

public typealias MTServerErrorClosure = () -> Void


/// 不要直接使用此类 配合ViewControllerExtension 使用
public class MTServerCrachView : UIControl{
    
    let imageView = UIImageView().then {
        $0.image = UIImage.imagePath(named: "serverCrach", bundle: Bundle.MTCategroy)
    }
    
    let text = UILabel().then {
        $0.text = "服务器秀逗了，点击重试"
        $0.textAlignment = .center
        $0.font = HelveticaNeueFont(14.0)
        $0.textColor = UIColor.init(hex: 0x666666)
    }
    
    
    var refreshClosure : MTServerErrorClosure?
    
    init(){
        super.init(frame: CGRect.zero)
        self.backgroundColor = MainPageBackgroundColor
        self.addSubview(imageView)
        self.addSubview(text)
        
        self.addTarget(self, action: #selector(tappedInView), for: .touchUpInside)
        
        imageView.snp.makeConstraints { (make) in
            make.centerX.equalTo(self)
            make.top.equalTo(AutoWidth(87.0))
        }
        
        text.snp.makeConstraints { (make) in
            make.centerX.equalTo(self)
            make.top.equalTo(imageView.snp.bottom).offset(47.0)
        }
    }
    
    @objc private func tappedInView() -> Void{
        if let closure = refreshClosure{
            closure()
        }
    }
    
    required public init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
